package com.sale.system.dubbo;


import com.sale.common.core.domain.R;
import com.sale.system.api.RemoteUnitService;
import com.sale.system.api.domain.SysAuxiliaryUnitDetail;
import com.sale.system.api.model.MaterialUnitDto;
import com.sale.system.service.ISysAuxiliaryUnitDetailService;
import com.sale.system.service.ISysAuxiliaryUnitService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Map;

/**
 * 获取单位信息
 */
@RequiredArgsConstructor
@Service
@DubboService
public class RemoteUnitServiceImpl implements RemoteUnitService {

    private final ISysAuxiliaryUnitService sysAuxiliaryUnitService;

    private final ISysAuxiliaryUnitDetailService sysAuxiliaryUnitDetailService;

    /**
     * 获取单位信息
     * @param id
     * @return
     */
    @Override
    public R<MaterialUnitDto> getUnitDataByCode(Long id) {
        return R.ok(sysAuxiliaryUnitService.getUnitDataByCode(id));
    }

    /**
     *
     * @param materialCode
     * @return
     */
    @Override
    public MaterialUnitDto getUnitByCode(String materialCode) {
        return sysAuxiliaryUnitService.getUnitByCode(materialCode);
    }

    /**
     * 根据物料编码查询出单位信息和辅助单位(返回map)
     */
    @Override
    public Map<String, MaterialUnitDto> getUnitByCodeToMap() {
        return sysAuxiliaryUnitDetailService.getUnitByCodeToMap();
    }

    /**
     * 返回多单位map集合(报表模块使用)
     */
    @Override
    public Map<Long, String> getUnitToMap() {
        return sysAuxiliaryUnitService.getUnitToMap();
    }

    /**
     * 获取多单位列表(单位转换使用)
     */
    @Override
    public List<SysAuxiliaryUnitDetail> getUnitByMaterialId(Long materialId) {
        return sysAuxiliaryUnitDetailService.getUnitByMaterialId(materialId);
    }
}
